package cn.com.jslh.boarpro.util;

import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.text.InputType;
import android.view.Gravity;
import android.widget.EditText;

/**
 * 作者：I_Gisvity on 2017/8/15 17:00
 * <p>
 * 邮箱：double0zhou@126.com
 */

public class InputDialogUtil {

    public interface DialogListener {
        public void getText(String s);
    }

    public static void showInputDialog(Context context, String title, String msg, final DialogListener dialogListener) {
    /*@setView 装入一个EditView
     */
        final EditText editText = new EditText((context));
        editText.setWidth(60);
        editText.setGravity(Gravity.CENTER);
        editText.setHint(msg);
        editText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
        AlertDialog.Builder inputDialog =
                new AlertDialog.Builder(context);
        inputDialog.setTitle(title).setView(editText);
        inputDialog.setPositiveButton("确定",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        if (editText.getText().toString().length() > 0) {
                            dialogListener.getText(editText.getText().toString());
                        }else {
                            dialogListener.getText("");
                        }
                    }
                }).show();
    }
}
